#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//	system("start https://www.lanqiao.cn/problems/19868/learning/");

    string s;
    cin >> s;

    int cntL, cntQ;
    cntL = cntQ = 0;

    int pre = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != s[pre]) {
            if(s[i] == 'Q')
                cntL += i - pre - 1;
            else
                cntQ += i - pre - 1;

            pre = i;
        } else if(i + 1 == s.size()) {
            if(s[i] == 'L')
                cntL += i + 1 - pre - 1;
            else
                cntQ += i + 1 - pre - 1;
        }
    }

    cout << 1ll * s.size() - max(cntQ, cntL);

    return 0;
}
